﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Markup;

using WpfApp4.Models.Config;

namespace WpfApp4.Models
{
    public class EnumConverter : MarkupExtension, IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if(value is OpenModel openModel)
            {
                return openModel.GetDescription();
            }
            return "";
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if(value is string openModel)
            {
                return EnumExtension.GetEnumByDescription<OpenModel>(openModel);
            }
            return OpenModel.CurrentWindow;
        }

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return this;
        }
    }
}
